package ca.llsutherland.nfl.persistence;

import ca.llsutherland.nfl.configuration.PoolConfiguration;

public class DatabaseConnectionManager {

	private AbstractDatabaseConnection databaseConnection;
    private static DatabaseConnectionManager instance = new DatabaseConnectionManager();

    public static DatabaseConnectionManager getInstance() {
        return instance ;
    }

    public void initialize() throws InstantiationException, IllegalAccessException, ClassNotFoundException{
        this.databaseConnection = (AbstractDatabaseConnection) PoolConfiguration.getInstance().getDatabaseConnection();
    }

    public AbstractDatabaseConnection getDatabaseConnection() {
    	if(this.databaseConnection == null){
    		try {
				initialize();
			} catch (Exception e) {
				e.printStackTrace();
			}
    	}
        return this.databaseConnection;
    }

    public void registerNewDomainObject(Long id, String tableName) {
    	this.databaseConnection.registerNewDomainObject(id, tableName);
    }

    public void deleteNewDomainObjects() {
        this.databaseConnection.deleteNewDomainObjects();
    }

    public void removeDomainObject(Long idToRemove) {
        this.databaseConnection.removeDomainObject(idToRemove);
    }
}
